package com.readingtree.library.security;

import org.slf4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017/4/14.
 */
@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint, InitializingBean {

    private static Logger logger = org.slf4j.LoggerFactory.getLogger(CustomAuthenticationEntryPoint.class);

    public CustomAuthenticationEntryPoint(){
    }

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        logger.error("CustomAuthenticationEntryPoint commence invoked");
        response.getWriter().print("you has not login");
    }

    @Override
    public void afterPropertiesSet() throws Exception {

    }
}
